Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Spring Context Accessor for Static Access to Tenant Properties #271

Conversation

wwelling
Copy link

@wwelling wwelling commented Dec 11, 2024

This PR introduces a new utility class, SpringContextAccessor, which provides static access to the Spring application context. This allows for the retrieval of beans, such as tenant properties, in a static manner. Additionally, a factory method has been added to OkapiRestTemplate to facilitate its creation and configuration using a builder pattern.

Key Changes:

  1. New Utility Class: SpringContextAccessor

    • Implements ApplicationContextAware to set the application context automatically when the Spring container starts.
    • Provides a static method getBean(Class<T> beanClass) to retrieve beans from the application context.
  2. Factory Method in OkapiRestTemplate

    • Introduces a static factory method build() for creating and configuring OkapiRestTemplate instances using a fluent API.
  3. Unit Tests

    • Added SpringContextAccessorTest to ensure the correct retrieval of tenant properties bean.
    • Utilizes SpringBootTest with mock web environment for testing.

Rationale:

  • Static Access to Beans: The SpringContextAccessor allows for easy and static access to Spring-managed beans, which is particularly useful for accessing tenant-specific properties across different parts of the application.

  • Fluent API for OkapiRestTemplate: The factory method enhances the usability of OkapiRestTemplate by providing a clear and concise way to instantiate and configure it.

  • Preventing Deserialization: Making the constructor of OkapiRestTemplate private prevents direct instantiation and deserialization, which enhances security by ensuring that instances are only created through the controlled factory method.

  • Improved Test Coverage: The added tests ensure that the new functionality works as expected and integrates well with the existing application context.

Additional Changes:

  • Minor test cleanup to improve code readability and maintainability.

@wwelling wwelling requested a review from kaladay December 11, 2024 01:17
@wwelling wwelling changed the title Add Spring context accessor for accessing tenant properties statically Add Spring Context Accessor for Static Access to Tenant Properties Dec 11, 2024
@kaladay kaladay deleted the branch investigation-2024_12_02-staging December 18, 2024 14:41
@kaladay kaladay closed this Dec 18, 2024
@wwelling wwelling deleted the investigation-2024_12_02-staging-spring-context-accessor branch December 19, 2024 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants